﻿using System;
using System.Web;
using System.Web.SessionState;

namespace nsadv.Statistic.Web.Notifications.Application
{
	public class ApplicationNotifier : IApplicationNotifier, IApplicationNotificationSource
	{
		public event EventHandler<ApplicationEventArgs> ApplicationStart;
		public event EventHandler<ApplicationEventArgs> ApplicationEnd;
		public event EventHandler<ApplicationErrorEventArgs> ApplicationError;
		public event EventHandler<SessionEventArgs> SessionStart;
		public event EventHandler<SessionEventArgs> SessionEnd;

		public void FireApplicationStart(HttpApplicationState application)
		{
			if (ApplicationStart != null)
				ApplicationStart(this, new ApplicationEventArgs { Application = application });
		}

		public void FireApplicationEnd(HttpApplicationState application)
		{
			if (ApplicationEnd != null)
				ApplicationEnd(this, new ApplicationEventArgs { Application = application });
		}

		public void FireApplicationError(HttpApplicationState application, Exception error)
		{
			if (ApplicationError != null)
				ApplicationError(this, new ApplicationErrorEventArgs { Application = application, Error = error });
		}

		public void FireSessionStart(HttpApplicationState application, HttpSessionState session)
		{
			if (SessionStart != null)
				SessionStart(this, new SessionEventArgs { Application = application, Session = session });
		}

		public void FireSessionEnd(HttpApplicationState application, HttpSessionState session)
		{
			if (SessionEnd != null)
				SessionEnd(this, new SessionEventArgs { Application = application, Session = session });
		}
	}
}
